<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="/webjars/jquery/3.6.0/dist/jquery.js"></script>
    <script src="/webjars/axios/0.26.1/dist/axios.js"></script>
    <style>
        table {
            border: black solid 1px;
            text-align: center;
            width: 800px;
        }
    </style>
</head>
<body>
<div id="app">
    <form action="" onsubmit="return false">
        <table align="center">
            <tr>
                <td>姓名</td>
                <td>
                    <input type="text" name="name" placeholder="请输入学生姓名">
                </td>
            </tr>
            <tr>
                <td>性别</td>
                <td>
                    男<input type="radio" name="sex" value="男">&nbsp;&nbsp;
                    女<input type="radio" name="sex" value="女">
                </td>
            </tr>
            <tr>
                <td>爱好</td>
                <td>
                    <input id="basketball" type="checkbox" name="hobby" value="篮球">
                    <label for="basketball">篮球</label>

                    <input id="football" type="checkbox" name="hobby" value="足球">
                    <label for="football">足球</label>

                    <input id="badminton" type="checkbox" name="hobby" value="羽毛球">
                    <label for="badminton">羽毛球</label>

                    <input id="tennis" type="checkbox" name="hobby" value="网球">
                    <label for="tennis">网球</label>
                </td>
            </tr>
            <tr>
                <td>课程</td>
                <td>
                    <span th:each="c:${courses}">
                        <input th:id="${c.id}" type="checkbox" name="courses" th:value="${c.id}">
                        <label th:for="${c.id}" th:text="${c.name}"></label>
                    </span>
                </td>
            </tr>
            <tr>
                <td colspan="2">
                    <button onclick="add()">【添加】</button>
                </td>
            </tr>
        </table>
    </form>
</div>
<script>
    function add() {
        let formDate = $('form').serialize();

        axios.post('/stu/add', formDate).then(resp => {

        }).catch((e)=>{
            console.log(e);
        })
    }
</script>
</body>
</html>